ray handler refactored