Added some comments. Added A check to main. Fixed uninitialized part in decoder.