Added some comments and a bit of code cleanup