merge new database code, fixes #9