Fixed a few esoteric bugs with plugin api
Removed a bunch of obsolete and superfluous code from implementation.