Move callback counting into single function.

Closes #246.