fixing writing to db