implement swap_with_next
refactor