structure the app function better