Refactoring + fix #2

Refactored and optimized the plugin and fixed #2