optimizations and docstrings