adding local, global variables, and nested loops