major refactoring; new data handling