bugfix in application of substitutions