Updated version, changed equality for states to use Equals