add docs and code refactor