Cleaned up the code further, including initializing all variables to ensure a proper restart.