code refactor and docs