making ghosts leave at the appropriate time