Refactored plugin code