serious refactoring / work in progress