Struct byval cleanup: add helper functions to reduce code duplication.