Swap elements function now iteraters correctly