Magic numbers

This cleans up the code from a lot of magic numbers.

I did not use a specific ticket number (just #000), but I can open one for it. I did not test against the apps (HPC is down). Just putting it here so people can look at it and comment.