refactor attempt to put function defs in one place
Additiona refactors, Jedi works again.