Refactored MATLAB code to use decoder function.