added first version of counter
Moved counterfn into cascalog.

Also cleaned up code so as not to distract from merge proposal.