Misplaced "end" statements