added some code for cleanliness of file handling