Massive documentation work and refactor