Found a bug - trailing invalid character causes index out of bounds..