Added more exception checks.

Used instanceof checks for JSON
Fixed strings using trim.