Data processing functions (complete, I think)