First version of ControlState support
merge upstream