fixed group by nil pointer