swap function done