modified unify function to take a substitution as an argument