refactored code to have method defined for reuse and update of params