Optimized samples class, more minor refactorings here and there.