Re-did zig-zag algorithm to make it easier to understand... and work.