Refactor code, update doc