Partly rewritten script.