Improved prefix test