Code refactored to reflect change 2310411: form_state is now a classed object.