Added needed synchronization blocks

I think I understand this synchronization & volatile thing correctly...