Added comments and did minor code cleanup