fixed having too many forloops