Add a datagrid state wrapper and clean up some code