started swap algorithm