code beautification procedures

took out redundant code in the 4 JSON calls, called a function instead
to clean up the code. added a few comments