Cleaned if statements and reduced duplication of defined vars

Using if/elseif rather than multiple ifs
Broke out postfields that were duplicated.
Broke out the query_string definition
Added choice to define json/xml as the responsetype