working version. Not lock-free