Trying to make extract_prefix code less magical