Clean up of main plugin code