implemented stage swapping