Fixed a bug where clearing could lead to crashing.