Refactor state module to reduce duplication