Modify the solve function