refactored app delegate