Updated to be a bit more const friendly. Also switched the linkage to be static since this function is file-local. No functional changes intended.