Add docstring and error handing