Refactor plugin and sample
After PR the plugin is refactored and updated. Code and semantic fixes.