reordered fns for clarity
bugfix: line problem 0 offset - loops were missing middle of array