Added locks for synchronization.