trying to implement pattern match