refactoring, adding support for multiple application phase 2