Recoded the main part of the plugin