Full js rewrite