moved sample stuff to outer loop