added better handling of foreign postMessages