Make use of context managers to safely close files