Fix bug that was causing program to freeze