fix SQL stuff; other minor edits