placing main loop in a proper if statement