Fixed a few issues. Added some comments.