Further refactoring of state.rb