it builds again... substantial refactoring done here.