major CSG refactoring and optimizations