Small changes to run Alexander Sherikov's code in matlab.