Code has been beautified for easier reading.