-Added comments

-Added a new preview (preview=1) param when calling the script to enable HTML visualization of the result, if the preview 
param is not used or not equal to 1, a JSON formated result is returned.

-Changed the previous return of the script from an array to a JSON formated object.

-Added a simple try..catch to return an error message as a result if something unexpected happens.