refactor plugin based on FichteFoll's comments