Extract validation and color derivation into separate functions.