Cleaned up calcState, also trying to merge properly this time.