would this not be nicer and safer as a pattern match?