Corrected misinterpretations and also formatted code.