used int for iteration count, simplified naive implementation