did some reordering, changed some comments, and removed some unused code