Refactor and code documentation