Refactored rm operation and wrote unit tests for it.