Updated the code to check the state on init