Efficiency tweaks

Condensed from three separate for loops to one (no reason for the
separate loops).