Fix a fatal bug in database