refactor rh_service.py for clarity, efficiency, and correctness