efficent counting