d5133b2 lots of additions and refactorings