close to finished, only lock-free is missing
(near) final version