fix unicode transcoding, add debug config option, improve scan