Refactored more data processing functions