Lot of work to clean variable names and make the code more constant overall.