cleanup and add tests for key id