WIP - major refactoring - almost ready for prime time
further refactoring
Merge branch 'refactorig'
killed a bug