Clean up RPL substitution code