Added some comments and code clean up