change method of updating GM in exact case and apply optimisation of dealing with the basis only at the end