revised and simplified plugin