Added checking for state changes in middle layers