Completey rewritten the plug-in