cleaner subsampling code