Refactor constants

I think this is now ready to be merged.