replaced try-catch with simple "if"