adding swapping, algortihm needs a second look