better algorithm of size counting