Some fixes and improvements

Some fixes and improvements