major refactoring to new style