Add logic to avoid exceptions from empty states.