Rewrote and shortened loops.