fix issue with missing last off statement
fix off-by-one (sample) error