fix fun-substitution to use pattern-matching