Finished 1st version of solve logic.