Condensed if statements corrected error causing program to hang