Changes to handle database errors