Refactor app code