Refactored into plugin
Added unit tests