Add docstrings, try to make code clearer