fix fundamental bug in substitution