fix bugs with encoding and another stuff