Working statistics gathering.
Refactors code.

Refs #117