Fixed bug in substitution.