Some incomplete rewriting of the cas code.