fix up quotes, use correct sql syntax, get reordering working, change variables for readability, code commenting