refactored the code: properly locating app user directory;
doing file IO at the top level