fixed previous bug, now the program properly halts