fixed the number of loops needed to be taken