added synchronization for Buffer