refactor rpn