optimized some operations, improved CG