Add tests and minor bug fixes

Tests added for:

* keys
* util
* visualize