Database integration - fixes and improvements