Fix StringIndexOutOfBoundsException, closes #112