Fix constants; add SQL error handling/logging