Fixed database update logic