rewriting hacks as js lib