Added comments and fixed subsampling bug on line 63