Refactored directory.rb