Refactor directory.rb