It seems like we're doing the exact same check in the if loops for both version 3 and version 4. Could we just extract this check to only happen once and catch both of those cases?