Refactored the main plugin