Complete rewrite to use Hashes