Bug fixings and improvements