almost working. we need to improve the swap function