fixed some crashes with bad indexes