Some little bug fixes and improvements