refactoring, adding support for multiple application phase 1