1. move localApp function to a single file;
2. some minor refactors;