added code to replace outerloop returns with continues