Update the decoding for encoded signature and fix some bugs that I found.