Implemented and applied 'position-aware line iterator' to simplify some operations