Fix for encoding. Minor changes to debugging script.