algorithm from 08.02.2014 implemented