Split recursive function into two separate functions, working on storing directories now