Refactored the computation of gmf by avoiding a few ifs