Cleanup; fixed counting bug