Change when clause to explicitly check for nil.