Refactor code, edit docstring