Reordering of code.
Changed encoding to return the similar exceptions to decode.