rewriting into js