Cleaned up CWD management code.