Loops are starting to work, still some issues with scope