Implement the rm command and do some refactoring