Working but still ugly

fixed problem with looping, and other conflicting varibles