Changed regex to use a wrapper, also tidied up various bits of plugin source