Performance tweaks to loops.