loads of encoding bugfixes