Handle invalid prefixes and use better assertions.