fix code to scan back to valid header instead of failing