fix the algorithm to recurse the directory tree