moved subsitution solver into its own function.