More documentation done, fixed some comments and a minor logic problem.