made more changes to loop code.