Gen. Petraeus ends command in Afghanistan