refactor the struct byte swapping to a helper function.