Updated to use documents and rewrote comments