Add null checks to handle exception throws