Add docstrings and refine some rules