Add docstring and remove redundant code