Neatened code, added some comments