Improve the solve code