prevent getting stuck if dir() returns itself

fixes #6