added some more comments, fixed some obvious errors