overhaul to subsample routine