Directory logic refactoring