This probably needs a docstring and it's own unit tests.