Almost ready for submission. Have commented the code appropriately.