Writes to database.