Added count (*) directly from database instead of select all and then use the size() of array