Fix trailing characters issue and specs.