Use if-else instead of try-except for perf reason