Fixed some obvious errors and added initialisation for some variables...