Data_state refactoring: removed most of the global variables.