Solve function