Added mutex protection for write calls