Clean up and add docstring