j/kestrel: bunch of refactoring