complete code refactoring for entire plugin