fix bugs in database.py