This needs a docstring explaining how it works.