working code with next best