Fixed a few issues, added some comments