Refactoring length_and_rest in one function to make it cleaner
Refactoring - rewrote decoding with length_and_rest