bulk of code, not including addons.