replaced try/except with if/else