Modified the code in response to Eric's suggestions. Tested it except for facebook. My forward account expired, so I can't run that app anymore to test it