Revamp polyfill and add tests