Several small fixes and improvements