Nested loops as well as one loop after another now work correctly