updated the solve method and improved style