first refactoring to support single_definition
templating init
too much
cleanup
some further improvements