tweaked line organization logic and made deletions work