Jwang refactor query encoding

just an aside -- since the extra comma is legal in Java, I tend to use it. Makes it easier when copying and pasting rows from these tables, since there's no special "last row" you have to worry about comma management on.