Refactor RPL substitution