fixed IndexError bug