try writing to db earlier