refactor and added AppDir to context