refactoring rpn