Started massive refactoring for performance and tweakability