Clean up DB code, remove some SQL injection holes.