added synchronized blocks for writes