Extract key parsing and add few tests.
Correct logging and failing tests.