Simplifying perform_substitution. Still 3 tests broken