advanced algorithm

Signed-off-by: tabatsky <e.tabatsky@gmail.com>