Fixed incorrect accounting for array length when checking which action t...

...o perform.