Fixed bug and swapping protection.