changed document.write to use document.createElement('script')