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.

Ps: I'm aware that it's a bit an ugly fix because of a lot of changes for something which should be changed in one place. I might later look into it how to simplify it.

//Edit: cc as well @smigielski, @jrbl