moved all "magic" at the top of definitions