Creating the trigger function