xbrl.py: general refactoring