Improved plugin loading code