Proper state threading and test (thanks @yallop)