swap logic