Wip escaping fix

This is a proposed fix for the issues #197, #114, #83, #76. 
Could you please test this fix @lucifer4o, @oxivanisher, @pstadler, @maennchen? 

Thanks.