Documented much of the code