all cases should be working, keeps track of nested repeat loops with stack