Fixed a minor bug and also added some more commenting.