major app clean up and refactoring