added spinlock to sync (there is bug still)