Moved the clean up code to after initialization.