Fixed bug that caused the program to stall