Inline some code and add docstrings