extract internalState and sharedState to their own files