DDF-399 added null checks and better error handling