rewrote plugin code with better menu handling