Close files after writing to them

Also contains some cleanup of master which is now back to 2.10.x (The community builds for 2.11.x are targeting a tag)