Add docstrings
Fix logic