replace try catch with better null checks