fixed small errors in program flow