code ported

wow, lets not mention RMGFormula.pdf