Fixed JavaScript scoping issue with IE8, closes #687