Replace nested ternery with if/elsif block