Complete the implementation of state.cpp. Untested.