Improve pattern match typing