Refactor code, add methods and documentation.