Removed unnecessary code in loops