build.py: refactoring