major refactoring in preparation for stable release