Cleaning up Matlab code
minor bug fix
Updated R code to reflect latest changes in prototype Matlab implementation