write to database fix