Fix state calculation