Adding unit tests, refactored logic for replace param json