Refactoring and doc improvment