move pattern matching to function guards