some refactor and docs