cleaned up code - class learns for nsamples at time