Adding comment header and program comments. Some code cleaning