start of major refactoring
more refactoring
templates, other goodies