Fix IE9 crash by checking for invalid index before accessing array

In odd scenarios, endOffset could be 0 which results in trying to access an array at index -1