copy-paste from original code.