Refactor open ended tests and fix some code for opaque keys