Moving code around and adding additional comments.
Fixed a wrong link.