Fixed a few things and added some commenting