insert try-catch and if logic