normalize encoding and fix a type bug