implemented escape algorithm