diff --git a/source/clique/collection.py b/source/clique/collection.py
index 0c3b296..db9276c 100644
--- a/source/clique/collection.py
+++ b/source/clique/collection.py
@@ -251,15 +251,25 @@ class Collection(object):
         else:
             data['padding'] = '%d'
 
-        if self.indexes:
+        if '{holes}' in pattern:
             data['holes'] = self.holes().format('{ranges}')
 
+        if '{range}' in pattern or '{ranges}' in pattern:
             indexes = list(self.indexes)
-            if len(indexes) == 1:
+            indexes_count = len(indexes)
+
+            if indexes_count == 0:
+                data['range'] = ''
+
+            elif indexes_count == 1:
                 data['range'] = '{0}'.format(indexes[0])
+
             else:
-                data['range'] = '{0}-{1}'.format(indexes[0], indexes[-1])
+                data['range'] = '{0}-{1}'.format(
+                    indexes[0], indexes[-1]
+                )
 
+        if '{ranges}' in pattern:
             separated = self.separate()
             if len(separated) > 1:
                 ranges = [collection.format('{range}')
@@ -270,11 +280,6 @@ class Collection(object):
 
             data['ranges'] = ', '.join(ranges)
 
-        else:
-            data['holes'] = ''
-            data['range'] = ''
-            data['ranges'] = ''
-
         return pattern.format(**data)
 
     def is_contiguous(self):

diff --git a/test/unit/test_collection.py b/test/unit/test_collection.py
index ce4daa7..11cb01e 100644
--- a/test/unit/test_collection.py
+++ b/test/unit/test_collection.py
@@ -2,6 +2,7 @@
 # :copyright: Copyright (c) 2013 Martin Pengelly-Phillips
 # :license: See LICENSE.txt.
 
+import sys
 import inspect
 
 import pytest
@@ -242,7 +243,6 @@ def test_remove_non_member():
     (PaddedCollection, '{range}', '1-12'),
     (PaddedCollection, '{ranges}', '1-3, 7, 9-12'),
     (PaddedCollection, '{holes}', '4-6, 8'),
-
 ])
 def test_format(CollectionCls, pattern, expected):
     '''Format collection according to pattern.'''
@@ -250,6 +250,25 @@ def test_format(CollectionCls, pattern, expected):
     assert collection.format(pattern) == expected
 
 
+def test_format_sparse_collection():
+    '''Format sparse collection without recursion error.'''
+    recursion_limit = sys.getrecursionlimit()
+    recursion_error_occurred = False
+
+    try:
+        collection = PaddedCollection(
+            indexes=set(range(0, recursion_limit * 2, 2))
+        )
+        collection.format()
+    except RuntimeError as error:
+        if 'maximum recursion depth exceeded' in str(error):
+            recursion_error_occurred = True
+        else:
+            raise
+
+    assert not recursion_error_occurred
+
+
 @pytest.mark.parametrize(('collection', 'expected'), [
     (PaddedCollection(indexes=set([])), True),
     (PaddedCollection(indexes=set([1])), True),

collection.format hits maximum recursion depth for collections with lots of holes.
The following code gives an example.

```python
paths = ["name.{0:04d}.jpg".format(x) for x in range(2000)[::2]]
collection = clique.assemble(paths)[0][0]
collection.format("{head}####{tail}")
```
test/unit/test_collection.py::test_format_sparse_collection
test/unit/test_collection.py::test_remove_non_member test/unit/test_collection.py::test_separate[non-contiguous test/unit/test_collection.py::test_is_compatible[incompatible test/unit/test_collection.py::test_compatible_merge[complimentary] test/unit/test_collection.py::test_holes[range test/unit/test_collection.py::test_comparisons[different test/unit/test_collection.py::test_format[PaddedCollection-{ranges}-1-3, test/unit/test_collection.py::test_is_compatible[compatible] test/unit/test_collection.py::test_holes[empty] test/unit/test_collection.py::test_contains[non-member test/unit/test_collection.py::test_compatible_merge[duplicates] test/unit/test_collection.py::test_is_contiguous[empty] test/unit/test_collection.py::test_match[padded-collection:unpadded test/unit/test_collection.py::test_add[unpadded-collection:padded test/unit/test_collection.py::test_add[padded-collection:unpadded test/unit/test_collection.py::test_format[PaddedCollection-{head}-/head.] test/unit/test_collection.py::test_holes[single test/unit/test_collection.py::test_add[padded-collection:padded test/unit/test_collection.py::test_is_contiguous[contiguous test/unit/test_collection.py::test_not_implemented_comparison test/unit/test_collection.py::test_format[PaddedCollection-{range}-1-12] test/unit/test_collection.py::test_format[PaddedCollection-{padding}-%04d] test/unit/test_collection.py::test_format[PaddedCollection-{holes}-4-6, test/unit/test_collection.py::test_is_contiguous[single] test/unit/test_collection.py::test_compatible_merge[both test/unit/test_collection.py::test_match[different test/unit/test_collection.py::test_str test/unit/test_collection.py::test_unsettable_indexes test/unit/test_collection.py::test_format[UnpaddedCollection-{padding}-%d] test/unit/test_collection.py::test_contains[different test/unit/test_collection.py::test_incompatible_merge[incompatible test/unit/test_collection.py::test_format[PaddedCollection-{tail}-.ext] test/unit/test_collection.py::test_separate[empty] test/unit/test_collection.py::test_add[unpadded-collection:unpadded test/unit/test_collection.py::test_repr test/unit/test_collection.py::test_match[padded-collection:padded test/unit/test_collection.py::test_change_property[padding-4-^head\\.(?P<index>(?P<padding>0*)\\d+?)\\.tail$-head.0001.tail] test/unit/test_collection.py::test_iterator[padded-collection] test/unit/test_collection.py::test_comparisons[equal] test/unit/test_collection.py::test_iterator[unpadded-collection] test/unit/test_collection.py::test_escaping_expression test/unit/test_collection.py::test_match[unpadded-collection:unpadded test/unit/test_collection.py::test_separate[single test/unit/test_collection.py::test_holes[multiple test/unit/test_collection.py::test_remove test/unit/test_collection.py::test_holes[contiguous test/unit/test_collection.py::test_holes[missing test/unit/test_collection.py::test_match[unpadded-collection:padded test/unit/test_collection.py::test_add_duplicate test/unit/test_collection.py::test_is_contiguous[non-contiguous] test/unit/test_collection.py::test_contains[valid test/unit/test_collection.py::test_separate[contiguous