Fixed counting bugs.