added some comments and output generation