fix escape processing, trim debug messages