Add resetSampleCount
A great deal of refactoring