Rewrote javascript - rough