Abstraction and changing if/then to match