These formulas changed from the original repo versions from the use of switch.
Again back to the original version.