refactor app code