Refactor subst_of_env to be tail-recursive in ML