Added some comments, minor code changes