updated rm function