Added decode functionality. Processed refactoring of code