Add error check when opening file