Copied extracted code from okdoki_applet.