Updated with check to the excess prefix character in the result.