refactoring: using os.walk() instead of recursion