Cleanup redundant and uneeded code
More cleanup
Fix handling of the last line
Clear empty lines at the end when clearing all whitespace.
Clear existing tags when updating lines