Prevent some exception under IE8

In some hard to reproduce cases exceptions are logged in the IE8 console:
Line 9165: "'length' is empty or not an object"
Line 14833: "Object required"

These exceptions are easily prevented. This pull request adds extra bounds checking.