Added proper error handling in case the file could not be read.
Also deleted input in case of an error.