error handling and deleteing files