Complete re-write of the plugin with tests

See #21