Extract the Directory logic into a Classs