refactored line inserting && added undo/redo mechanism