Few more JS fixes, and move some more stuff over to the plugin. See #244. Closes #243