Revert "Revert "Database Bug Fix""

This reverts commit 2c66e147e646d9b8d3dafd3ee6d52307963a7c85.