Fix ArrayIndexOutOfBounds and avoid NPE
Merge pull request #158 from rostafiychuk/utilfix

Fix ArrayIndexOutOfBounds and avoid NPE