updated for correct data swapping