try to use compareAndSwap to reduce the locked code, but need to do some performance tests and probably to check if I can't use channels instead