Improved sub-directory logic.