writing relevant data to database