Rewrote fixes in plain JavaScript