amend directory walking function