build_db.py: Multiple improvements