writes to db