improve memory utilization of directory traversal