Neatened code, added some additional initialisation.