Unwanted shut down of outputs.

You haven't explicitly set the switch pin to INPUT.
You haven't enabled the pullup resistor on the switch pin.

You haven't told us how the switch is wired.

  buttonState = val;  // save the new state in our variable

Matching names, like currState and prevState, make a lot more sense, and really appear to be logically related, than buttonState and val.