Fixed counting functions.