Refactoring rp functions