synchronizing the write method so we avoid the parelism problem