Improved conditional logic per suggestions from @chrisroberts