Factor out the helper functions to avoid creating new functions every call.