Rewrote some sections and added comments.