Some refactoring for cleaner application flow