Continuing structural changes

Minor changes in structure and moved plugin specific code to plugins.js