fixed error codes and rm()