adding docstring and code cleanup