bug fix when using plugin installed from repository, some refactoring