refactor out common code in parameter validation