Fix nested-directory bug. Make functions private