Avoid recursion; fix counting