Fixing OutOfBoundsException