added missing null checks
small polishing