Refactoring and fixed error handling
Refactoring
Refactored plugin manager
Added test