solution to finding an optimal state change attempt, as well as an enhanced algorithm