fix conditional logic