Added two API calls for creating COUNT statements.

I added two API calls for setting up COUNT statments and
also refactored the associated parts of the code. These API
function are still in flux and may change.