Fix number of states not being correctly counted.
Fix detach of a view's element, destroying it.