corrected the decoding algorithm for remaining length and added a test to make sure encoding matches decoding