New JavaScript implementation