require_dependencies should be sorted for each directory.
Improve code (@ujifgc's suggestion).