Move main logic into Application