Neaten graph mapper

* Uses `collections.defaultdict` as the prime data type in the mapper.
* Raises `ValueError` when a parameter is invalid.
* Raises `KeyError` when a key is invalid.

Requires review please.