Complete re-write of the plugin with tests