Refactor and docs