Refactored out directory management.