written swap function