Adding better error logging for database