Refactor to use real trees and not nested hashes