Added subsampling functionality, still needs testing.