Rework database.py