optimization for countChildren method