fixed syntax error that was blocking CHECK, fixed three bugs introduced by changing while loops to for loops/