changed implementation after looking up canonical behavior of rpn