bugfix. write out the finished database