Refactoring main application