Work in progress. turned into plugin, added unit tests