ApplicationState bug and test fixes