implemented very-very-very slow algorithm