Arduino master to arduino slave code not working correctly

so I've narrowed my problem down to an issue with trying to have the device have both master and slave capabilities. so i took a new approach, and now i can get it to work perfectly as either master or slave, but not both. i know you cant do both at the same time, but i had assumed you could switch between them, in an OR configuration. however, i am having issues with that.

Basically, this function on the slave:

void switchI2CMode(bool asMaster) {
  Wire.end(); // End current I2C operation to reconfigure
  
  if (asMaster) {
    // Configure as I2C master
    Wire.begin(); // Start I2C as master
 }
  
  else {
    // Configure as I2C slave
    Wire.begin(0x20); // join i2c bus with address 0x20 as a slave 
    Wire.onReceive(receiveEvent); // register event
    Wire.onRequest(requestEvent); // Register the onRequest event handler
  }
}

is supposed to select between master and slave mode. however Wire.onReceive(receiveEvent) & Wire.onRequest(requestEvent) only work when initialized in the setup routine, and once the device is switched into master mode, it ceased ever being able to function as a slave (until it is reset). does anyone know a workaround to this? microcontroller is a SAMD21G18A. Its on a custom board, so using a second sercom is not possible without a revised board.