Fixed wrongly swaped thread and global indexes