add docstring and doctest.