Updated function to recurse directories