first pass at modularizing the matchswitch code