Updated with new code and formulae