encoding fixes, remove unused code
restore encoding code that was miscut