Nested while loops now working.
Made some progress with backtracking, but mysteries remain.