Refactor, and add pydoc