reworked functions & added CGInv