added detection of wrongly escaped quotes at the end of the string