Most of work moving enums into their own files and adding MagicValues system, apply recent fixes from other branches