Removed unused includes and removed the recursive structure of the algorithm. Now it uses a stack to push and pop directories during processing.