build_db.py: Several improvements