Replaced reduce with select/count