Added error checking when opening file