Refactor for greater cross-browser portability