revised version that was indended for conditional $to variables based on if main site.