Refactored substitution system