use pattern match instead of var