Converting the script to a flexible plugin