fixed index out of bounds error