added some comments, some formatting