eliminated unnecessary swap function