Refactor plugin a bit