Added error handling when the file is unable to be opened