Refactoring + fix #2, #4

Refactored and optimized the plugin and fixed #2

Edit: also fixed #4.