app.main refactor