Make use of encoding module, new way of storing debug mode variable,

Minor cleanup