Reworked part1 to be consistent with rest of parts.  Also, it's significantly easier to understand the loops now