consolidated much code into plugins_loaded hooks