Cleans up and simplifies decoding code