Documtation and refactor