add numIterations as a parameter + misc cleanup in samples