Add docstrings and avoid multiple returns