Moved most functions into the plugin class