Implement database test, and fix bugs in database.py