Added a function to open and close files