made swap a function