changed from globals to state objects returned from main functions