Rewrite to JS based generator