And some general cleanup to related constants, etc.
* Remove duplicate code * fix incorrect formulas is some places * add comments