fixes bug - array index out of bound and corrects test