Replace if/else with fetch