Cleaning

Changes to make Sonar hate us less...
Removed some magic numbers
Changed singular occurence variables to be local rather than global