Some general fixes and improvements