added isRetreating as well as other bug fixes
Merge branch 'dev2'