Some changes to prevent NilClass errors.