several bug fixings