fix for handling IndexOutOfBoundsException