edited rm function