Replace if/else with case and elim redundant resource