fixing countInner() and iterate()