Additional error checking and deletion of files for shell script