Algorithm is working now