fixed some initialisation and closing issues