perfected counting with walk method