Add JSON encoding & 1st Code Cleanup of log functions