The method is borrowed from here(ru): [1]