Updated and tidied up plugin code.