Wrote solver function