factor out state-related utility code