Added error checking for (most) db calls