Updated the open function to pass filenames and not filehandlers