first draft of ktest refactorings, might not pass tests yet