rewrote preprocess_sample largely to bsxfun
refactored whole loop into bsxfun/vector boolean stuff