using trimJSON instead of substring
corrected comments