added some comments, fixed format