Bug fix: expect() not handling flags correctly