add docstring and make small bug fixes