added docstring and minor remodeling