use array append and join instead of string-concatenation and trim
encode complex q params to json automatically; add flat