This is a complex function that handles all the potential cases that can happen with legacy remote state, new configurations, etc.