refactored to meet project requirement of encapsulating a function in json