fixed the display order of definitions, and a fair bit of code clean up