Partially rewrite plugin unloading

Now it should work with latest mcore