Fixed history state bug, cleaned up history stuff a bit.