replaced sleeps with latchBarriers, various fixes after code reviews