Improve plugin logic & do a little clean