fixed a lot indentations, further escaping and code improvements