Major rewrite of the formula code
still incomplete but direction of travel is clear