This seems to be a copy-paste, could it be reorganized and moved to a function that is called from multiple places?