added some comments, fixed some functions