added annotations and docstrings.