simplified and using plain js