refactor countChildren