Clean up and improve debug statements.
Removed dependency on BC key encoding.
Added ability to count filtered results.