fixed bug where program would freeze under certain conditions