SQL and minor edits