* refactor of new function, use a subroutine to reduce cyclomatic complexity