Renamed variables to match Matlab implementation