converted to vanilla js