fix getNextAction to look further into the stack