replaced try-catch with ifs