Corrected RPN algorithm