Move things around and fix for loop var