add support for explicit key (and some refactoring)