Refactoring countParams function