fix legal-states

legal-states shouldn't return nil values so fix the loop.