Fixing parseFormula algorithm issues