Added comments and general code cleanup