Refactor and doc