Refactor and update docs