Fixing some problems with encoding. Not all yet