Close files after reading
Improve readability
Remove end tags first