Fixed bug finding keys.
Added tests.