cleaning and refactorization of app.py and build.py