fix critical bug in retreat code