swap function working