added test and docstrings + cleanup