Pure JS version