added some comments and changed some formatting