Rewrote parts of the plugin, added env scope handling.