Updated hadapi.py file, with docstrings and better syntax