Refactor directory construction