Clean up, update, and rails-ify directory code