edited to allow multiple databases.