Bugfix in addActivityToStack and improved waitForActivity