synchronize in places to avoid deadlocks