refactor hillclimbing algorithm