optimizing loops for final testing