Refactor state cache - extract inner classes