updated conditional logic