Rewrote more of loop protection to carefully walk new lines

This ensures we catch multi-line loop conditions, and fixes #725.