add docstrings and fix formatting