added escape and insert method, made condition more resilient