initial code for saving to database, not yet tested