bug fixes for database.