Bugfixes on escaping algorithm