Extract common plugin code