refactored to have jsonFilename in global scope and used by both functions