added try-catch blocks around calcs in loglik