Rewrite Dictionary class.

This commit rewrites `Dictionary` class into something more C++-like
and less of an hack.