porting to vanilla js version