fixed infinate loop that caused program to crash