Added in some checks to prevent a handful of IndexOutOfBound and NullPointer exceptions