Copied code from idp/html