Fix possible NullPointerException and ArrayIndexOutOfBoundsException.
Merge pull request #28 from supergillis/master

Fix possible NullPointerException and ArrayIndexOutOfBoundsException.