Cleanup in main and shell