Merge pull request #52 from leods/master

Avoid StringIndexOutOfBoundsException