Refined the decode algorithm.
Added more difficult test case.