changed try catch statements to if else