updated the solve method