rewrote plugin; cleaned code