Added new logic for calculate the number of elements