Commented to explain the algorithms somewhat