problems fixed

now the algorithm work