Rewriting this into a pattern match may improve readability.